package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;

import com.itheima.dao.SetMealDao;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;

import java.util.List;
import java.util.Map;
@Service(interfaceClass=ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    @Autowired
    private SetMealDao setMealDao;

    /**
     * 通过运营数据统计可以展示出体检机构的运营情况，包括会员数据、预约到诊数据、热门套餐等信息。本章节就是要通过一个表         格的形式来展示这些运营数据
     * /report/getBusinessReportData.do
     *
     * @return
     */
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        HashMap<String, Object> map = new HashMap<>();
//    1. 当天日期：
        String today = DateUtils.parseDate2String(DateUtils.getToday(), "yyyy-MM-dd");
        map.put("reportDate", today);
//    2. 查找当天新增会员
        Integer numberToday = memberDao.findMemberBytoday(today);
        map.put("todayNewMember", numberToday);
//    3. 查找总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        map.put("totalMember", totalMember);
//    4. 查找本周新增会员数
        String thisWeek = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeek);
        map.put("thisWeekNewMember", thisWeekNewMember);
//    5. 查找本月新增会员数
        String thismonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(thismonth);
        map.put("thisMonthNewMember", thisMonthNewMember);
//    6.   今日预约数
        Integer todayOrderNumber = orderDao.findOrderBytoday(today);
        map.put("todayOrderNumber", todayOrderNumber);
//    7.   今日到诊断数量
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(today);
        map.put("todayVisitsNumber", todayVisitsNumber);
//    8.   本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(thisWeek);
        map.put("thisWeekOrderNumber", thisWeekOrderNumber);
//    9.   本周到诊数量
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(thisWeek);
        map.put("thisWeekVisitsNumber", thisWeekVisitsNumber);
//    10.  本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(thismonth);
        map.put("thisMonthOrderNumber", thisMonthOrderNumber);
//    11.  本月到诊断数量
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(thismonth);
        map.put("thisMonthVisitsNumber", thisMonthVisitsNumber);
//     12. 套餐数量最多,占比
       List<Map<String,Object>> hotSetmeal=setMealDao.findMaxOrder();
       map.put("hotSetmeal", hotSetmeal);
       return map;
    }
}
